package com.task.jobcontroller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.communication.json.JsonResult;
import com.entity.Task;
import com.entity.Terminal;
import com.interfaces.TaskDao;
import com.task.jobcontroller.entity.JobEntity;
import com.task.manage.Job_Server;
import com.task.service.TaskService;

import io.swagger.annotations.ApiOperation;

@Controller
@RequestMapping(value = "/JobController")
public class JobController {

	@Autowired
	private TaskDao taskDao;

	@Autowired
	private TaskService taskService;

	@Autowired
	private Job_Server job_server;

	@ApiOperation(value = "直抄数据发送", notes = "")
	@RequestMapping(value = "/jobrun", method = RequestMethod.POST)
	@ResponseBody
	public JsonResult<JobEntity> sent(@RequestBody JsonResult<JobEntity> jsonResult, HttpServletRequest request) {

		JobEntity jobEntity = jsonResult.getData();

		Task task = taskDao.findOne(Integer.valueOf(jobEntity.getTaskid()));

		List<Terminal> terminals = taskService.listTerminalByTaskid(Integer.valueOf(task.getTaskid()));
		for (Terminal terminal : terminals) {
			job_server.Jobaddone(Integer.valueOf(task.getTasktype()), task.getJobtype(),
					String.valueOf(task.getTaskid()),
					String.valueOf(terminal.getTerminalid()) + ";" + jobEntity.getRemark());
		}

		jsonResult.setMessage("补抄");

		return jsonResult;
	}

}
